package com.mtrhz.xxx.controller;

import java.util.concurrent.CompletableFuture;

import org.apache.dubbo.rpc.RpcContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.mtrhz.esb.inteface.sso.TokenService;

@RestController
public class AsyncConsumerController {
	
    //@Reference(version = "1.0.0") //放弃注解配置，原因：无法细化到方法级别
	@Autowired
    private TokenService asyncTokenService;
    
    @RequestMapping("/asyncGetToekn")
	public String getToekn() {
    	
    	// 异步,在xml 对应<dubbo:reference id="asyncTokenService" interface="com.hg.esb.inteface.sso.TokenService" version="1.0.0" async="true"></dubbo:reference>
    	asyncTokenService.getToken("grant_type", "scope", "client_id", "client_secret");
        CompletableFuture<String> tokenFuture = RpcContext.getContext().getCompletableFuture();
        tokenFuture.whenComplete((retValue, exception) -> {
            if (exception == null) {
                System.out.println(retValue);
            } else {
                exception.printStackTrace();
            }
        });
		return "";
	}
}
